#if 0
#include <iostream>
using namespace std;
long long nums[15][15];
int main() {
    int n, m;    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
        {
            cin >> nums[i][j];
        }
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++)
        {
            cout << nums[j][i] << ' ';
        }
        cout << endl;
    }
}
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * max water
     * @param arr int整型vector the array
     * @return long长整型
     */
    int left_max[200005];
    int right_max[200005];
    long long maxWater(vector<int>& arr) {
        // write code here
        int size = arr.size();
        int _max = 0;
        for (int i = 0; i < size; i++) {
            _max = max(_max, arr[i]);
            left_max[i] = _max;
        }
        _max = 0;
        for (int i = size - 1; i >= 0; i--) {
            _max = max(_max, arr[i]);
            right_max[i] = _max;
        }
        long long ret = 0;
        for (int i = 0; i < size; i++) {
            ret += max(0, min(left_max[i], right_max[i]) - arr[i]);
        }
        return ret;
    }
};
#include <iostream>

using namespace std;
int cnt[5];
int m, x, y;
bool same[13][13];
int ret = 0;
int side[13];
bool isSame(int pos, int i) {
    for (int j = 1; j < pos; j++) {
        if (same[pos][j] == true && i != side[j])
            return true;
    }
    return false;
}
void dfs(int pos) {
    if (pos > 12) { ret++; return; }
    for (int i = 1; i <= 4; i++) {
        if (cnt[i] == 0) continue;
        if (isSame(pos, i))   continue;
        cnt[i]--;
        side[pos] = i;
        dfs(pos + 1);
        cnt[i]++;
    }
}
int main() {
    for (int i = 1; i <= 4; i++)  cin >> cnt[i];
    cin >> m;
    while (m--) {
        cin >> x >> y;
        same[x][y] = same[y][x] = true;
    }
    dfs(1);
    cout << ret << endl;
}

int _a, _b, _c, _d;
int na, nb, nc, nd, m;
int arr[13];
int ret = 0;
map<int, vector<int>> mm;
void dfs(int i) {
    if (i == 13) {
        ret++;
        return;
    }
    if (_a < na) {
        bool t = false;
        for (auto e : mm[i]) {
            if (arr[e] != 1) {
                t = true;
                break;
            }
        }
        if (t == false) {
            arr[i] = 1;
            _a++;
            dfs(i + 1);
            _a--;
        }
    }
    if (_b < nb) {
        bool t = false;
        for (auto e : mm[i]) {
            if (arr[e] != 2) {
                t = true;
                break;
            }
        }
        if (t == false) {
            arr[i] = 2;
            _b++;
            dfs(i + 1);
            _b--;
        }
    }
    if (_c < nc) {
        bool t = false;
        for (auto e : mm[i]) {
            if (arr[e] != 3) {
                t = true;
                break;
            }
        }
        if (t == false) {
            arr[i] = 3;
            _c++;
            dfs(i + 1);
            _c--;
        }
    }
    if (_d < nd) {
        bool t = false;
        for (auto e : mm[i]) {
            if (arr[e] != 4) {
                t = true;
                break;
            }
        }
        if (t == false) {
            arr[i] = 4;
            _d++;
            dfs(i + 1);
            _d--;
        }
    }
}
int main() {
    cin >> na >> nb >> nc >> nd >> m;
    int x, y;
    while (m--) {
        cin >> x >> y;
        if (x > y) swap(x, y); // x < y;

        mm[y].push_back(x);
    }
    dfs(1);
    cout << ret << endl;
    system("pasue");
}
#endif